package com.tianqu.tms.entity;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.tianqu.tms.core.base.TmsEntity;
import com.tianqu.tms.core.exception.TmsDaoException;
import com.tianqu.tms.core.exception.TmsException;
import com.tianqu.tms.dao.TmsDao;
import com.tianqu.tms.dao.TransferSettlementInfoDao;
import com.tianqu.tms.dao.TransferTicketdInfoDaoImp;
import com.tianqu.tms.dto.TransferSettlementInfoDto;
import com.tianqu.tms.dto.TransferTicketdInfoDto;

public class TransferSettlementInfo extends TmsEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1857537657277596146L;

	private int id;
	private int settleId;// 结算日期ID
	private int settleUserId;// 结算人ID
	private int settletype;// 结算种类
	private int receivable;// 应收/
	private int receivableBack;//应退金额
	private int paid;// 实收/
	private int paidBack;//实退金额
	private int insertUserId;// 结算受理人ID
	private Timestamp insertTime;// 结算受理日期
	
	private int ysPrice;
	private int ssPrice;

	public void insertTransferTicketdInfo(TransferTicketdInfoDto dto) throws TmsDaoException{
		TransferTicketdInfoDaoImp uDao = (TransferTicketdInfoDaoImp) TmsDao.getInstance(TmsDao.TMS_TRANSFER_TICKETD_INFO);
		uDao.insertTransferTicketdInfo(dto);
	}
	
	
	public void insertSettleInfo(TransferSettlementInfo entity) throws TmsDaoException
	{
		TransferSettlementInfoDao uDao = (TransferSettlementInfoDao) TmsDao.getInstance(TmsDao.TMS_TRANSFER_SETTLEMENT_INFO);
		TransferSettlementInfoDto dto = new TransferSettlementInfoDto();
		dto = setDtoFromEntity(dto, entity);
		uDao.insertSettleInfo(dto);
	}
	private TransferSettlementInfoDto setDtoFromEntity(TransferSettlementInfoDto dto,TransferSettlementInfo entity)
	{
		dto.setSettleId(entity.getSettleId());
		dto.setSettleUserId(entity.getSettleUserId());
		dto.setReceivable(entity.getReceivable());
		dto.setPaid(entity.getPaid());
		dto.setInsertUserId(entity.getInsertUserId());
		dto.setSettletype(entity.getSettletype());
		dto.setReceivableBack(entity.getReceivableBack());
		dto.setPaidBack(entity.getPaidBack());
		return dto;
	}
	public List getChargePersonInfoBySettleId(String id)throws TmsDaoException
	{
		TransferSettlementInfoDao uDao = (TransferSettlementInfoDao) TmsDao.getInstance(TmsDao.TMS_TRANSFER_SETTLEMENT_INFO);
		List<TransferSettlementInfoDto> list = uDao.getChargePersonInfoBySettleId(id);
		List entityList = null;
		if(list.size()>0)
		{
			entityList = new ArrayList();
			for(int i=0;i<list.size();i++)
			{
				TransferSettlementInfoDto dto = (TransferSettlementInfoDto)list.get(i);
				if(dto.getInsertUserId() > 0)
				{
					User user = new User();
					user = user.getUserInfoById(dto.getInsertUserId());
					Map map = new HashMap();
					map.put("insertUserId", String.valueOf(dto.getInsertUserId()));
					map.put("realName", user.getRealName());
					entityList.add(map);
				}
			}
		}
		return entityList;
	}
	public TransferSettlementInfo getYPriceByUserId(String userid,int type,String settleId)throws TmsDaoException
	{
		TransferSettlementInfoDao uDao = (TransferSettlementInfoDao) TmsDao.getInstance(TmsDao.TMS_TRANSFER_SETTLEMENT_INFO);
		
		TransferSettlementInfoDto dto = new TransferSettlementInfoDto();
		dto = uDao.getYPriceByUserId(Integer.parseInt(userid),type,settleId);
		
		TransferSettlementInfo entity = new TransferSettlementInfo();
		entity.setYsPrice(dto.getYsPrice());
		entity.setSsPrice(dto.getSsPrice());
		return entity;
	}
	public TransferSettlementInfo getTotlePriceByUserId(String userid,String settleId)throws TmsDaoException
	{
		TransferSettlementInfoDao uDao = (TransferSettlementInfoDao) TmsDao.getInstance(TmsDao.TMS_TRANSFER_SETTLEMENT_INFO);
		
		TransferSettlementInfoDto dto = new TransferSettlementInfoDto();
		dto = uDao.getTotlePriceByUserId(Integer.parseInt(userid),settleId);
		
		TransferSettlementInfo entity = new TransferSettlementInfo();
		entity.setYsPrice(dto.getYsPrice());
		entity.setSsPrice(dto.getSsPrice());
		return entity;
	}
	public void deleteSettleBySettleId(int settleId,int insertUserId)throws TmsDaoException
	{
		TransferSettlementInfoDao uDao = (TransferSettlementInfoDao) TmsDao.getInstance(TmsDao.TMS_TRANSFER_SETTLEMENT_INFO);
		uDao.deleteSettleBySettleId(settleId,insertUserId);
	}
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public int getSettleId() {
		return settleId;
	}

	public void setSettleId(int settleId) {
		this.settleId = settleId;
	}

	public int getSettleUserId() {
		return settleUserId;
	}

	public void setSettleUserId(int settleUserId) {
		this.settleUserId = settleUserId;
	}

	public int getSettletype() {
		return settletype;
	}

	public void setSettletype(int settletype) {
		this.settletype = settletype;
	}

	public int getReceivable() {
		return receivable;
	}

	public void setReceivable(int receivable) {
		this.receivable = receivable;
	}

	public int getReceivableBack() {
		return receivableBack;
	}


	public void setReceivableBack(int receivableBack) {
		this.receivableBack = receivableBack;
	}


	public int getPaidBack() {
		return paidBack;
	}


	public void setPaidBack(int paidBack) {
		this.paidBack = paidBack;
	}


	public int getPaid() {
		return paid;
	}

	public void setPaid(int paid) {
		this.paid = paid;
	}

	public int getInsertUserId() {
		return insertUserId;
	}

	public void setInsertUserId(int insertUserId) {
		this.insertUserId = insertUserId;
	}

	public Timestamp getInsertTime() {
		return insertTime;
	}

	public void setInsertTime(Timestamp insertTime) {
		this.insertTime = insertTime;
	}

	public int getYsPrice() {
		return ysPrice;
	}
	public void setYsPrice(int ysPrice) {
		this.ysPrice = ysPrice;
	}
	public int getSsPrice() {
		return ssPrice;
	}
	public void setSsPrice(int ssPrice) {
		this.ssPrice = ssPrice;
	}
	@Override
	public void save() throws TmsDaoException, TmsException {
		// TODO Auto-generated method stub

	}

}
